import { http } from '@/utils/axios/init'

const prefix = '/common/Rest/commonFlow'
export interface BasicResponseModel<T = any> {
  code: number
  msg: string
  data: T
}
export function saveFlow(params) {
  return http.request<BasicResponseModel>({
    url: '/common/Rest/commonFlow/save',
    method: 'POST',
    params
  })
}

// 使用空白模板
export function useBlankFlowTemplate(params) {
  return http.request<BasicResponseModel>(
    {
      url: '/common/Rest/commonFlow/useBlankFlowTemplate',
      method: 'POST',
      params
    },
    {
      successMessageText: '保存成功'
    }
  )
}

// CTMS使用空白模板
export function ctmsUseBlankFlowTemplate(params) {
  return http.request<BasicResponseModel>(
    {
      url: '/ctms/Rest/commonFlow/useBlankFlowTemplate',
      method: 'POST',
      params
    },
    {
      successMessageText: '保存成功'
    }
  )
}

export function listByPage(params) {
  return http.request<BasicResponseModel>({
    url: '/common/Rest/commonFlow/listByPage',
    method: 'GET',
    params
  })
}
export function getDetails(params) {
  return http.request<BasicResponseModel>({
    url: '/common/Rest/commonFlow/getFlowInfoById',
    method: 'GET',
    params
  })
}
// ctms端获取已选流程的详情
export function getCtmsDetails(params) {
  return http.request<BasicResponseModel>({
    url: '/ctms/Rest/commonFlow/getFlowInfoById',
    method: 'GET',
    params
  })
}
export function update(params) {
  return http.request<BasicResponseModel>({
    url: '/common/Rest/commonFlow/update',
    method: 'POST',
    params
  })
}

// 更新CTMS端已选流程
export function updateCtms(params) {
  return http.request<BasicResponseModel>({
    url: '/ctms/Rest/commonFlow/update',
    method: 'POST',
    params
  })
}
export function remove(params) {
  return http.request<BasicResponseModel>({
    url: '/common/Rest/commonFlow/delete',
    method: 'POST',
    params
  })
}
// ctms删除已选的流程
export function ctmsRemove(params) {
  return http.request<BasicResponseModel>({
    url: '/ctms/Rest/commonFlow/delete',
    method: 'POST',
    params
  })
}
export function updateStatus(params) {
  return http.request<BasicResponseModel>({
    url: '/common/Rest/commonFlow/updateStatus',
    method: 'POST',
    params
  })
}
export function copyFlow(params) {
  return http.request<BasicResponseModel>(
    {
      url: '/common/Rest/commonFlow/copyFlow',
      method: 'POST',
      params
    },
    {
      successMessageText: '复制成功'
    }
  )
}

export function getOrgUserList(params) {
  return http.request<BasicResponseModel>({
    url: '/system/Rest/user/getOrgUserList',
    method: 'GET',
    params
  })
}
export function getRoleList(params) {
  return http.request<BasicResponseModel>({
    url: '/system/Rest/role/list/page',
    method: 'GET',
    params
  })
}

// 获取审批流模板
export function getFlowTemplate(params) {
  return http.request<BasicResponseModel>({
    url: `${prefix}/getFlowTemplate`,
    method: 'GET',
    params
  })
}

// 选择审批流模板
export function chooseFlow(params) {
  return http.request<BasicResponseModel>(
    {
      url: `/common/Rest/commonFlow/chooseFlow`,
      method: 'post',
      params
    },
    {
      successMessageText: '选择成功'
    }
  )
}

// 选择审批流模板(应用)
export function ctmsChooseFlow(params) {
  return http.request<BasicResponseModel>(
    {
      url: `/ctms/Rest/commonFlow/chooseFlow`,
      method: 'post',
      params
    },
    {
      successMessageText: '选择成功'
    }
  )
}

// 获取流程进度
export function getFlowProgress(params) {
  return http.request<BasicResponseModel>({
    url: `/ctms/Rest/projectTaskFlow/flowRecord`,
    method: 'GET',
    params
  })
}

//根据任务id获取任务流程（项目中心端）
export function getTaskFlow(params) {
  return http.request<BasicResponseModel>({
    url: `/ctms/Rest/projectTaskFlow/list`,
    method: 'GET',
    params
  })
}

//根据任务id获取任务流程（项目进度模板端）
export function getSopSpeedTaskFlow(params) {
  return http.request<BasicResponseModel>({
    url: `/common/Rest/sopSpeedFlow/list`,
    method: 'GET',
    params
  })
}

// 获取流程定义中需要发起人设置节点审批人的节点
export function getFlowNode(params) {
  return http.request<BasicResponseModel>({
    url: `/ctms/Rest/projectTaskFlow/getFlowDynamicApprovals`,
    method: 'GET',
    params
  })
}

// 启动流程
export function startFlow(params) {
  return http.request<BasicResponseModel>(
    {
      url: `/ctms/Rest/projectTaskFlow/startWorkFlow`,
      method: 'POST',
      params
    },
    {
      successMessageText: '提交成功'
    }
  )
}

// 审批流程
export function approveFlow(params) {
  return http.request<BasicResponseModel>(
    {
      url: `/ctms/Rest/projectTaskFlow/auditWorkFlow`,
      method: 'POST',
      timeout: 1000 * 20,
      params
    },
    {
      successMessageText: '审批成功'
    }
  )
}

// 退回流程
export function backFlow(params) {
  return http.request<BasicResponseModel>(
    {
      url: `/ctms/Rest/projectTaskFlow/returnWorkFlow`,
      method: 'POST',
      params
    },
    {
      successMessageText: '退回成功'
    }
  )
}
// 拒绝流程
export function rejectFlow(params) {
  return http.request<BasicResponseModel>(
    {
      url: `/ctms/Rest/projectTaskFlow/rejectProcess`,
      method: 'POST',
      params
    },
    {
      successMessageText: '拒绝成功'
    }
  )
}

// 获取下一节点所有信息
export function getNextNode(params) {
  return http.request<BasicResponseModel>({
    url: `/ctms/Rest/projectTaskFlow/getNextNodeInfo`,
    method: 'GET',
    params
  })
}

// 获取下一节点所有信息(药房端)
export function getPharmacyDynamicApprovals(params) {
  return http.request<BasicResponseModel>({
    url: `/pharmacy/Rest/drugFlow/getFlowDynamicApprovals`,
    method: 'GET',
    params
  })
}

// 获取需要发起人设置节点审批人的节点
export function getFlowDynamicApprovals(params) {
  return http.request<BasicResponseModel>({
    url: `/ctms/Rest/projectTaskFlow/getFlowDynamicApprovals`,
    method: 'GET',
    params
  })
}

// 获取任务审批详情接口（含动态审批人信息）
export function getTaskFlowDetail(params) {
  return http.request<BasicResponseModel>({
    url: `/ctms/Rest/projectTaskFlow/getComplexInfoById`,
    method: 'GET',
    params
  })
}

// 获取药房任务进度
export function getPharmacyTaskProgress(params) {
  return http.request<BasicResponseModel>({
    url: `/pharmacy/Rest/taskProgress/list`,
    method: 'get',
    params
  })
}
